﻿using System;
using System.Data.SqlClient;

namespace IFD2
{
    public partial class FltInventory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["ACL"].ToString().IndexOf("IA2") < 0)
                {
                    Response.Redirect("Unauthorized.aspx");
                }
                if (Request.QueryString["flt_no"] != null)
                {
                    hidFltNo1.Value = Request.QueryString["flt_no"].ToString();
                    hidFltDate1.Value = Convert.ToDateTime(Request.QueryString["flt_date"]).ToShortDateString();
                    lblAirline.Text = Session["AIRLINE"].ToString();//Request.QueryString["airline"].ToString();
                    hidAirline.Value = lblAirline.Text;
                    txtFltNo.Text = hidFltNo1.Value;
                    txtFltDate.Text = hidFltDate1.Value;
                    hidFltNo2.Value = hidFltNo1.Value;
                    hidFltDate2.Value = hidFltDate1.Value;
                    hidFltNo3.Value = hidFltNo1.Value;
                    hidFltDate3.Value = hidFltDate1.Value;
                    hidFltNo4.Value = hidFltNo1.Value;
                    hidFltDate4.Value = hidFltDate1.Value;
                    Session["FLT_NO"] = hidFltNo1.Value;
                    Session["FLT_DATE"] = hidFltDate1.Value;
                }
                else if (Session["FLT_NO"] != null && Session["FLT_DATE"] != null)
                {
                    hidFltNo1.Value = Session["FLT_NO"].ToString();
                    hidFltDate1.Value = Convert.ToDateTime(Session["FLT_DATE"].ToString()).ToShortDateString();
                    hidFltDate1.Value.Replace('/', '-');
                    txtFltNo.Text = hidFltNo1.Value;
                    txtFltDate.Text = hidFltDate1.Value;
                    hidFltNo2.Value = hidFltNo1.Value;
                    hidFltDate2.Value = hidFltDate1.Value;
                    hidFltNo3.Value = hidFltNo1.Value;
                    hidFltDate3.Value = hidFltDate1.Value;
                    hidFltNo4.Value = hidFltNo1.Value;
                    hidFltDate4.Value = hidFltDate1.Value;
                    lblAirline.Text = Session["AIRLINE"].ToString();
                    hidAirline.Value = lblAirline.Text;
                }
                else
                {
                    lblAirline.Text = Session["AIRLINE"].ToString();
                    hidAirline.Value = lblAirline.Text;
                }
            }

            lblError1.Text = "";
            lblError.Text = "";
            lblError2.Text = "";
            btnAdd.Attributes.Add("onclick", "javascript:return confirm('Are you sure?');");
            btnSetMaxOpen1.Attributes.Add("onclick", "javascript:return confirm('Are you sure?');");
            btnRecalculate.Attributes.Add("onclick", "javascript:return confirm('Are you sure?');");
            btnUpdate.Attributes.Add("onclick", "javascript:return confirm('Are you sure?');");
            btnCalculateAvail.Attributes.Add("onclick", "javascript:return confirm('Are you sure?');");
            btnDelete.Attributes.Add("onclick", "javascript:return confirm('Are you sure?');");
            //btnSetStatus.Attributes.Add("onclick", "javascript:return confirm('Are you sure?');");
            //btnSetTailNo.Attributes.Add("onclick", "javascript:return confirm('Are you sure?');");
            btnDayProductSailing.Attributes.Add("onclick", "get_ajax()");
            //Chart1.ImageStorageMode = System.Web.UI.DataVisualization.Charting.ImageStorageMode.UseImageLocation;
            //Chart1.ChartAreas[0].AxisY.Title = "PAX";
            //Chart1.ChartAreas[0].AxisY2.Title = "Avg. Price -" + lstCurrencies.SelectedValue;
            //Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线
            //Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;//不显示竖着的分割线
            //Chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;//不显示竖着的分割线
        }

        protected void btnRefresh1_Click(object sender, EventArgs e)
        {
            GridView1.DataBind();
        }
        protected void btnSetMaxOpen1_Click(object sender, EventArgs e)
        {
            if (Session["ACL"].ToString().IndexOf("IA4") < 0)
            {
                lblError.Text = "Unauthorized!";
                return;
            }
            int ret_code;
            string key;
            string[] strArray;
            if (Request.Form["KEY1"] == null)
            {
                lblError.Text = "Please select the record you wanted.";
                return;
            }
            key = Request.Form["KEY1"];
            strArray = key.Split('|');

            SqlCommand cmd = new SqlCommand();
            lblError1.Text = "";
            try
            {
                cmd.CommandText = "bll_flt_set_cabin";
                SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
                para = cmd.Parameters.AddWithValue("@flt_no", strArray[1]);
                para = cmd.Parameters.AddWithValue("@flt_date", strArray[2]);
                para = cmd.Parameters.AddWithValue("@airport", strArray[3]);
                para = cmd.Parameters.AddWithValue("@cabin", strArray[4]);
                para = cmd.Parameters.AddWithValue("@max_opn", txtMaxOpen1.Text);
                //para = cmd.Parameters.AddWithValue("@blk", txtBlk1.Text);
                para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
                para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());

                ret_code = TinyDAL.Exec(ref cmd);
                if (ret_code == 0)
                {
                    lblError1.Text = "Done.";
                    GridView1.DataBind();
                }
                else if (ret_code == 1)
                    lblError1.Text = "Updating failed!";
                else
                    lblError1.Text = "Error " + ret_code.ToString() + " !";
            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    lblError1.Text = ex.Message;
                else
                    lblError1.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
                return;
            }


        }

        /*****************************************************************/

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (Session["ACL"].ToString().IndexOf("IA4") < 0)
            {
                lblError.Text = "Unauthorized!";
                return;
            }
            txtMaxOpn2.Text = txtMaxOpn2.Text.Trim().ToUpper();
            int ret_code;
            bool is_batch = false;
            string key, buf, ori, des, class_open = "";
            string[] Array;
            try
            {
                int.Parse(txtMaxOpn2.Text);
            }
            catch (Exception ex)
            {
                is_batch = true;
            }

            if (is_batch)
            {
                ret_code = txtMaxOpn2.Text.IndexOf('/');
                if (ret_code >= 0 && ret_code <= txtMaxOpn2.Text.Length - 4)
                {
                    buf = txtMaxOpn2.Text.Substring(0, ret_code);
                    class_open = txtMaxOpn2.Text.Substring(ret_code + 1);
                    Array = buf.Split('-');
                    if (Array.Length == 2)
                    {
                        ori = Array[0];
                        des = Array[1];
                    }
                    else
                    {
                        lblError.Text = "Invalid format!";
                        return;
                    }

                }
                else
                {
                    lblError.Text = "Invalid format!";
                    return;
                }
            }
            else
            {
                if (Request.Form["KEY"] == null)
                {
                    lblError.Text = "Please select the record you wanted.";
                    return;
                }
                key = Request.Form["KEY"];
                Array = key.Split('|');
                ori = Array[2];
                des = Array[3];
            }
            SqlCommand cmd = new SqlCommand();
            lblError.Text = "";
            try
            {
                if (!is_batch)
                    cmd.CommandText = "bll_flt_set_class";
                else
                    cmd.CommandText = "bll_flt_batch_set_class_open_value";
                SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
                para = cmd.Parameters.AddWithValue("@flt_no", hidFltNo2.Value);
                para = cmd.Parameters.AddWithValue("@flt_date", hidFltDate2.Value);
                para = cmd.Parameters.AddWithValue("@ori_airport", ori);
                para = cmd.Parameters.AddWithValue("@des_airport", des);
                if (is_batch)
                    para = cmd.Parameters.AddWithValue("@class_open", class_open);
                else
                {
                    para = cmd.Parameters.AddWithValue("@class", Array[4]);
                    para = cmd.Parameters.AddWithValue("@max_opn", txtMaxOpn2.Text);
                }
                //para = cmd.Parameters.AddWithValue("@class_sn",txtClassSn.Text);
                if (chkNested.Checked)
                    para = cmd.Parameters.AddWithValue("@nested", 1);
                else
                    para = cmd.Parameters.AddWithValue("@nested", 0);
                //para = cmd.Parameters.AddWithValue("@market_airline", lstStatus2.SelectedValue);
                //para = cmd.Parameters.AddWithValue("@status", lstStatus2.SelectedValue);

                //para = cmd.Parameters.AddWithValue("@blk", txtBlk2.Text);
                //if (chkUseDcp2.Checked)
                //    para = cmd.Parameters.AddWithValue("@class_dcp", lstDcp2.SelectedValue);
                //else
                //    para = cmd.Parameters.AddWithValue("@class_dcp", "-");
                para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
                para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());

                ret_code = TinyDAL.Exec(ref cmd);
                if (is_batch)
                {
                    if (ret_code == 0)
                    {
                        lblError.Text = "Done.";
                        GridView2.DataBind();
                    }
                    else if (ret_code == 1)
                        lblError.Text = "At least one class area format is invalid!";
                    else if (ret_code == 2)
                        lblError.Text = "At least one class area lost ':'!";
                    else if (ret_code == 3)
                        lblError.Text = "At least one class open is not numeric!";
                    else if (ret_code == 4)
                        lblError.Text = "At least one class updating is failed!";
                    else
                        lblError.Text = "Error " + ret_code.ToString() + " !";
                }
                else
                {
                    if (ret_code == 0)
                    {
                        lblError.Text = "Done.";
                        GridView2.DataBind();
                    }
                    else if (ret_code == 1)
                        lblError.Text = "Updating failed!";
                    else
                        lblError.Text = "Error " + ret_code.ToString() + " !";
                }
            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    lblError.Text = ex.Message;
                else
                    lblError.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
                return;
            }


        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            //需检查是否有相关订座，否则可能丢失订座记录！
            //方案一：不删除，置0即可。
            //方案二：如果尚未有订该舱的订单及机票，可以删除，否则删除失败。
            if (Session["ACL"].ToString().IndexOf("IA4") < 0)
            {
                lblError.Text = "Unauthorized!";
                return;
            }
            int ret_code;
            string key;
            string[] strArray;
            if (Request.Form["KEY"] == null)
            {
                lblError.Text = "Please select the record you wanted.";
                return;
            }
            key = Request.Form["KEY"];
            strArray = key.Split('|');

            SqlCommand cmd = new SqlCommand();
            lblError.Text = "";
            try
            {
                cmd.CommandText = "bll_flt_delete_class";
                SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
                para = cmd.Parameters.AddWithValue("@flt_no", strArray[0]);
                para = cmd.Parameters.AddWithValue("@flt_date", strArray[1]);
                para = cmd.Parameters.AddWithValue("@class", lstStatus.SelectedValue);
                para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
                para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());
                ret_code = TinyDAL.Exec(ref cmd);
                if (ret_code == 0)
                {
                    lblError.Text = "Done.";
                    GridView2.DataBind();
                }
                else if (ret_code == 1)
                    lblError.Text = "Class booking is not empty, deleting failed!";
                //else if (ret_code == 2)
                //    lblError.Text = "There is at least one effective booking in this class! Can not delete!";
                //else if (ret_code == 3)
                //    lblError.Text = "There is at least one effective ticket in this class! Can not delete!";
                else
                    lblError.Text = "Error " + ret_code.ToString() + " !";
            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    lblError.Text = ex.Message;
                else
                    lblError.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
                return;
            }
        }
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            GridView2.DataBind();
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Session["ACL"].ToString().IndexOf("IA4") < 0)
            {
                lblError.Text = "Unauthorized!";
                return;
            }
            int ret_code;
            SqlCommand cmd = new SqlCommand();
            lblError.Text = "";
            try
            {
                cmd.CommandText = "bll_flt_add_class";
                SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
                para = cmd.Parameters.AddWithValue("@flt_no", txtFltNo.Text);
                para = cmd.Parameters.AddWithValue("@flt_date", txtFltDate.Text);
                para = cmd.Parameters.AddWithValue("@ori_airport", lstOri.SelectedValue);
                para = cmd.Parameters.AddWithValue("@des_airport", lstDes.SelectedValue);
                //para = cmd.Parameters.AddWithValue("@cabin", lstCabins.SelectedValue);
                para = cmd.Parameters.AddWithValue("@class", lstClasses.SelectedValue);
                para = cmd.Parameters.AddWithValue("@market_airline", lstAirines.SelectedValue);
                if (chkNested2.Checked)
                    para = cmd.Parameters.AddWithValue("@nested", 1);
                else
                    para = cmd.Parameters.AddWithValue("@nested", 0);
                para = cmd.Parameters.AddWithValue("@status", lstStatus.SelectedValue);
                para = cmd.Parameters.AddWithValue("@max_opn", txtMaxOpn.Text);
                //para = cmd.Parameters.AddWithValue("@blk", txtBlk.Text);
                //if (chkUseDcp.Checked)
                //    para = cmd.Parameters.AddWithValue("@class_dcp", lstDcp.SelectedValue);
                //else
                //    para = cmd.Parameters.AddWithValue("@class_dcp", "-");
                para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
                para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());

                ret_code = TinyDAL.Exec(ref cmd);
                if (ret_code == 0)
                {
                    lblError.Text = "Done.";
                    GridView2.DataBind();
                }
                else if (ret_code == 1)
                    lblError.Text = "Adding failed!";
                else
                    lblError.Text = "Error " + ret_code.ToString() + " !";
            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    lblError.Text = ex.Message;
                else
                    lblError.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
                return;
            }


        }

        protected void btnRecalculate_Click(object sender, EventArgs e)
        {
            if (Session["ACL"].ToString().IndexOf("IA4") < 0)
            {
                lblError.Text = "Unauthorized!";
                return;
            }
            lblError.Text = "";
            int ret_code;
            SqlCommand cmd = new SqlCommand("bll_flt_rebuild_inventory");
            SqlParameter para = cmd.Parameters.AddWithValue("@flt_date", txtFltDate.Text);
            para = cmd.Parameters.AddWithValue("@flt_no", txtFltNo.Text);
            para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
            para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
            para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());
            try
            {
                ret_code = TinyDAL.Exec(ref cmd);
                if (ret_code == 0)
                {
                    GridView1.DataBind();
                    GridView2.DataBind();
                    lblError.Text = "Done.";
                }
                else
                    lblError.Text = "Error " + ret_code.ToString() + "! Contact system adminstartor!";

            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    lblError.Text = ex.Message;
                else
                    lblError.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
                return;
            }
        }

        protected void btnCalculateAvail_Click(object sender, EventArgs e)
        {
            if (Session["ACL"].ToString().IndexOf("IA4") < 0)
            {
                lblError.Text = "Unauthorized!";
                return;
            }
            lblError.Text = "";
            int ret_code;
            SqlCommand cmd = new SqlCommand("bll_flt_rebuild_class_nesting");
            SqlParameter para = cmd.Parameters.AddWithValue("@flt_date", txtFltDate.Text);
            para = cmd.Parameters.AddWithValue("@flt_no", txtFltNo.Text);
            para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
            //para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
            //para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());
            try
            {
                ret_code = TinyDAL.Exec(ref cmd);
                if (ret_code == 0)
                {
                    GridView2.DataBind();
                    lblError.Text = "Done.";
                }
                else
                    lblError.Text = "Error " + ret_code.ToString() + "! Contact system adminstartor!";

            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    lblError.Text = ex.Message;
                else
                    lblError.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
                return;
            }
        }
        protected void btnRefreshFltNotes_Click(object sender, EventArgs e)
        {
            gvNotes.DataBind();
        }
        protected void btnAddNote_Click(object sender, EventArgs e)
        {
            if (Session["ACL"].ToString().IndexOf("IA4") < 0)
            {
                lblError.Text = "Unauthorized!";
                return;
            }
            int ret_code;
            SqlCommand cmd = new SqlCommand();
            lblError.Text = "";
            try
            {
                cmd.CommandText = "bll_flt_add_note";
                SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
                para = cmd.Parameters.AddWithValue("@flt_no", hidFltNo3.Value);
                para = cmd.Parameters.AddWithValue("@flt_date", hidFltDate3.Value);
                para = cmd.Parameters.AddWithValue("@note", txtNewNote.Text);
                para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
                ret_code = TinyDAL.Exec(ref cmd);
                if (ret_code == 0)
                {
                    lblNoteError.Text = "Done.";
                    gvNotes.DataBind();
                }
                else if (ret_code == 1)
                {
                    lblNoteError.Text = "Adding failed!";
                    return;
                }
                else
                {
                    lblNoteError.Text = "Error " + ret_code.ToString() + " !";
                    return;
                }
            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    lblError.Text = ex.Message;
                else
                    lblError.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
                return;
            }


        }
        protected void lbtnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime.Parse(txtFltDate.Text);
            }
            catch
            {
                lblError1.Text = "Invalid date format!";
                txtFltDate.Text = "";
                return;
            }
            hidFltNo1.Value = txtFltNo.Text;
            hidFltDate1.Value = txtFltDate.Text;
            hidFltNo2.Value = hidFltNo1.Value;
            hidFltDate2.Value = hidFltDate1.Value;
            hidFltNo3.Value = hidFltNo1.Value;
            hidFltDate3.Value = hidFltDate1.Value;
            hidFltNo4.Value = hidFltNo1.Value;
            hidFltDate4.Value = hidFltDate1.Value;
            Session["FLT_NO"] = hidFltNo1.Value;
            Session["FLT_DATE"] = hidFltDate1.Value;
            GridView3.DataBind();
            GridView1.DataBind();
            GridView2.DataBind();
            btnRefreshChart_Click(sender, e);
        }
        protected void btnDetails_Click(object sender, EventArgs e)
        {
            //Response.Redirect("class_dbf.aspx?KEY=" + lstDcp2.SelectedValue);
        }
        protected void btnSetDBF_Click(object sender, EventArgs e)
        {
            //if (Session["ACL"].ToString().IndexOf("AK8") < 0)
            //{
            //    lblError.Text = "Unauthorized!";
            //    return;
            //}
            //int ret_code;
            //string key;
            //string[] strArray;
            //if (Request.Form["KEY"] == null)
            //{
            //    lblError.Text = "Please select the record you wanted.";
            //    return;
            //}
            //key = Request.Form["KEY"];
            //strArray = key.Split('|');

            //SqlCommand cmd = new SqlCommand();
            //lblError.Text = "";
            //try
            //{
            //    cmd.CommandText = "bll_flt_set-class_dbf_X";
            //    SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
            //    para = cmd.Parameters.AddWithValue("@flt_no", strArray[0]);
            //    para = cmd.Parameters.AddWithValue("@flt_date", strArray[1]);
            //    para = cmd.Parameters.AddWithValue("@ori_airport", strArray[2]);
            //    para = cmd.Parameters.AddWithValue("@des_airport", strArray[3]);
            //    para = cmd.Parameters.AddWithValue("@class", strArray[4]);
            //    if (chkUseDcp2.Checked)
            //        para = cmd.Parameters.AddWithValue("@class_dbf", lstDcp2.SelectedValue);
            //    else
            //        para = cmd.Parameters.AddWithValue("@class_dbf", "-");
            //    para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
            //    para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());

            //    ret_code = TinyDAL.Exec(ref cmd);
            //    if (ret_code == 0)
            //    {
            //        lblError.Text = "Done.";
            //        GridView2.DataBind();
            //    }
            //    else if (ret_code == 1)
            //        lblError.Text = "Setting failed!";
            //    else
            //        lblError.Text = "Error:" + ret_code.ToString() ;
            //}
            //catch (Exception ex)
            //{
            //    if (Application["DEBUG"].ToString() == "1")
            //        lblError.Text = ex.Message;
            //    else
            //        lblError.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
            //    return;
            //}
        }
        protected void btnProducts_Click(object sender, EventArgs e)
        {
            //if (Session["ACL"].ToString().IndexOf("AK8") < 0)
            //{
            //    lblError.Text = "Unauthorized!";
            //    return;
            //}
            string key;
            string[] strArray;
            if (Request.Form["KEY"] == null)
            {
                lblError.Text = "Please select the class you wanted.";
                return;
            }
            key = Request.Form["KEY"];
            strArray = key.Split('|');
            Response.Redirect("ClassAvailProducts.aspx?flt_no=" + strArray[0] + "&flt_date=" + strArray[1] + "&ori=" + strArray[2] + "&des=" + strArray[3] + "&class=" + strArray[4]);
        }
        protected void btnSetClassAttributes_Click(object sender, EventArgs e)
        {
            if (Session["ACL"].ToString().IndexOf("IA4") < 0)
            {
                lblError.Text = "Unauthorized!";
                return;
            }
            int ret_code;
            string key;
            string[] strArray;
            if (Request.Form["KEY"] == null)
            {
                lblError.Text = "Please select the record you wanted.";
                return;
            }
            key = Request.Form["KEY"];
            strArray = key.Split('|');

            SqlCommand cmd = new SqlCommand();
            lblError.Text = "";
            try
            {
                cmd.CommandText = "bll_flt_set_class_attributes";
                SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
                para = cmd.Parameters.AddWithValue("@flt_no", strArray[0]);
                para = cmd.Parameters.AddWithValue("@flt_date", strArray[1]);
                para = cmd.Parameters.AddWithValue("@ori_airport", strArray[2]);
                para = cmd.Parameters.AddWithValue("@des_airport", strArray[3]);
                para = cmd.Parameters.AddWithValue("@class", strArray[4]);
                para = cmd.Parameters.AddWithValue("@class_sn", txtClassSn.Text);
                //if (chkNested.Checked)
                //    para = cmd.Parameters.AddWithValue("@nested", 1);
                //else
                //    para = cmd.Parameters.AddWithValue("@nested", 0);
                para = cmd.Parameters.AddWithValue("@market_airline", lstAirines2.SelectedValue);
                para = cmd.Parameters.AddWithValue("@status", lstStatus2.SelectedValue);
                //para = cmd.Parameters.AddWithValue("@max_opn", txtMaxOpn2.Text);
                //para = cmd.Parameters.AddWithValue("@blk", txtBlk2.Text);
                //if (chkUseDcp2.Checked)
                //    para = cmd.Parameters.AddWithValue("@class_dcp", lstDcp2.SelectedValue);
                //else
                //    para = cmd.Parameters.AddWithValue("@class_dcp", "-");
                para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
                para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());

                ret_code = TinyDAL.Exec(ref cmd);
                if (ret_code == 0)
                {
                    lblError.Text = "Done.";
                    GridView2.DataBind();
                }
                else if (ret_code == 1)
                    lblError.Text = "Updating failed!";
                else
                    lblError.Text = "Error " + ret_code.ToString() + " !";
            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    lblError.Text = ex.Message;
                else
                    lblError.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
                return;
            }
        }
        protected void btnSaleIndex_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltSaleIndex.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }
        protected void btnRoute_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltRoute.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }
        protected void btnLog_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltLog.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }
        protected void btnNotPaid_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltNotPaidOrders.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }
        protected void btnStandBy_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltCandidates.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }
        protected void btnExpired_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltExpiredOrders.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }
        protected void btnTickets_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltTickets.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }
        protected void btnCancelled_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltCancelledOrders.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }
        //protected void btnSetStatus_Click(object sender, EventArgs e)
        //{
        //    if (Session["ACL"].ToString().IndexOf("IA3") < 0)
        //    {
        //        lblError2.Text = "Unauthorized!";
        //        return;
        //    }
        //    int ret_code;

        //    if(lstStatus3.SelectedValue=="?")
        //    {
        //        lblError2.Text = "Please select the new Status!";
        //        return;
        //    }

        //    SqlCommand cmd = new SqlCommand();
        //    try
        //    {
        //        cmd.CommandText = "bll_flt_set_status";
        //        SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
        //        para = cmd.Parameters.AddWithValue("@flt_no", hidFltNo4.Value);
        //        para = cmd.Parameters.AddWithValue("@flt_date", hidFltDate4.Value);
        //        para = cmd.Parameters.AddWithValue("@status", lstStatus3.SelectedValue);
        //        //para = cmd.Parameters.AddWithValue("@type", lstFltTypes.SelectedValue);
        //        para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
        //        para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());

        //        ret_code = TinyDAL.Exec(ref cmd);
        //        if (ret_code == 0)
        //        {
        //            lblError2.Text = "Done.";
        //            GridView3.DataBind();
        //        }
        //        else if (ret_code == 1)
        //            lblError2.Text = "Updating failed!";
        //        else if (ret_code == 2)
        //            lblError2.Text = "Invalid status code!";
        //        else
        //            lblError2.Text = "Error " + ret_code.ToString() + " !";
        //    }
        //    catch (Exception ex)
        //    {
        //        if (Application["DEBUG"].ToString() == "1")
        //            lblError2.Text = ex.Message;
        //        else
        //            lblError2.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
        //    }
        //}
        //protected void btnSetTailNo_Click(object sender, EventArgs e)
        //{
        //    //此应为离港功能？执飞飞机座位数对销售有作用，所以为座控职能！
        //    if (Session["ACL"].ToString().IndexOf("IA3") < 0)
        //    {
        //        lblError2.Text = "unauthorized.aspx";
        //        return;
        //    }
        //    int ret_code;

        //    SqlCommand cmd = new SqlCommand();
        //    try
        //    {
        //        cmd.CommandText = "bll_flt_set_aircraft";
        //        SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
        //        para = cmd.Parameters.AddWithValue("@flt_no", hidFltNo4.Value);
        //        para = cmd.Parameters.AddWithValue("@flt_date", hidFltDate4.Value);
        //        para = cmd.Parameters.AddWithValue("@aircraft", lstTailNo.SelectedValue);
        //        para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
        //        para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());
        //        ret_code = TinyDAL.Exec(ref cmd);
        //        if (ret_code == 0)
        //        {
        //            lblError2.Text = "Done. Please check Cabin/Class and Departure Data.";
        //            GridView3.DataBind();
        //            btnRefresh1_Click(sender, e);
        //        }
        //        else if (ret_code == 1)
        //            lblError2.Text = "Failed! Flt route not found!";
        //        else if (ret_code == 2)
        //            lblError2.Text = "Adding new cabin failed!";
        //        else if (ret_code == 3)
        //            lblError2.Text = "Updating tail number failed!";
        //        else if (ret_code == 4)
        //            lblError2.Text = "Please lock the flight before changing aircraft!";
        //        else if (ret_code == 5)
        //            lblError2.Text = "Failed! Check aircraft cabin data!";
        //        else
        //            lblError2.Text = "Error " + ret_code.ToString() + " !";
        //    }
        //    catch (Exception ex)
        //    {
        //        if (Application["DEBUG"].ToString() == "1")
        //            lblError2.Text = ex.Message;
        //        else
        //            lblError2.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
        //    }
        //}


        protected void lstAirines2_DataBound(object sender, EventArgs e)
        {
            lstAirines2.SelectedValue = Session["AIRLINE"].ToString();
        }
        protected void lstAirines_DataBinding(object sender, EventArgs e)
        {
            lstAirines.SelectedValue = Session["AIRLINE"].ToString();
        }

        protected void btnRefreshChart_Click(object sender, EventArgs e)
        {
            //为了解决IIS下MS Chart出错：This will bypass chart image handler but you will lose privacy,multi-worker process and web farms handling.
            //Chart1.ImageStorageMode = System.Web.UI.DataVisualization.Charting.ImageStorageMode.UseImageLocation;

            Chart1.ChartAreas[0].AxisY.Title = "PAX";
            Chart1.ChartAreas[0].AxisY2.Title = "Avg. Price -" + lstCurrencies.SelectedValue;
            Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线
            Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;//不显示竖着的分割线
            Chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;//不显示竖着的分割线
            Chart1.DataBind();
        }
        protected void btnDupOrders_Click(object sender, EventArgs e)
        {
            Response.Redirect("FltDupBookings.aspx?flt_no=" + hidFltNo4.Value + "&flt_date=" + hidFltDate4.Value);
        }

        //protected void btnSetTypes_Click(object sender, EventArgs e)
        //{
        //    if (Session["ACL"].ToString().IndexOf("IA3") < 0)
        //    {
        //        lblError2.Text = "unauthorized.aspx";
        //        return;
        //    }
        //    if (lstSurchargeTypes.SelectedValue == "?" || lstFltTypes.SelectedValue == "?")
        //    {
        //        lblError.Text = "Please select FlightType and SurchargeType!";
        //        return;
        //    }
        //    int ret_code;

        //    SqlCommand cmd = new SqlCommand();
        //    try
        //    {
        //        cmd.CommandText = "bll_flt_set_types";
        //        SqlParameter para = cmd.Parameters.AddWithValue("@airline", Session["AIRLINE"].ToString());
        //        para = cmd.Parameters.AddWithValue("@flt_no", hidFltNo4.Value);
        //        para = cmd.Parameters.AddWithValue("@flt_date", hidFltDate4.Value);
        //        para = cmd.Parameters.AddWithValue("@flt_type", lstFltTypes.SelectedValue);
        //        para = cmd.Parameters.AddWithValue("@surcharge_type", lstSurchargeTypes.SelectedValue);
        //        para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
        //        para = cmd.Parameters.AddWithValue("@ip_addr", Request.UserHostAddress.ToString());
        //        lstFltTypes.SelectedValue = "?";
        //        lstSurchargeTypes.SelectedValue = "?";
        //        ret_code = TinyDAL.Exec(ref cmd);
        //        if (ret_code == 0)
        //        {
        //            lblError2.Text = "Done.";
        //            GridView3.DataBind();
        //            btnRefresh1_Click(sender, e);
        //        }
        //        else if (ret_code == 1)
        //            lblError2.Text = "Setting failed!";
        //        else
        //            lblError2.Text = "Error " + ret_code.ToString() + " !";
        //    }
        //    catch (Exception ex)
        //    {
        //        if (Application["DEBUG"].ToString() == "1")
        //            lblError2.Text = ex.Message;
        //        else
        //            lblError2.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
        //    }
        //}

    }
}